package com.customer.service;

import com.customer.dao.customerDao;
import com.customer.entity.customer;
import com.customer.feign.walletFeign;
import com.wallet.entity.wallet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class customerServiceImpl implements customerService{

    @Autowired
    private customerDao dao;

    @Autowired
    private walletFeign feign;

    @Override
    public customer Registry(String username, String password) {
        customer c = dao.findByUsername(username);
        if(c==null)
        {
            c.setUsername(username);
            c.setPassword(password);
            return dao.save(c);
        }
        return null;
    }

    @Override
    public customer Login(String username, String password) {
        customer c = dao.findByUsernameAndAndPassword(username,password);
        if(c!=null)
        {
            feign.create(c.getCid());
        }
        return c;
    }

    @Override
    public void delete(customer c) {
        dao.delete(c);
    }

    @Override
    public customer update(customer c) {
        return dao.save(c);
    }

    public String findAllwallets()
    {
        return feign.find();
    }
}
